package com.iMusic.presentationLayer;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.iMusic.businessLogicLayer.Account;
import com.iMusic.businessLogicLayer.Cart;
import com.iMusic.businessLogicLayer.Order;
import com.iMusic.businessLogicLayer.Payment;
import com.iMusic.businessLogicLayer.orderStatus.OrderStatus;
import com.iMusic.integrationLayer.BankInterface;
import com.iMusic.util.UserMessages;

public class SearchOrder extends HttpServlet  {

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession session = request.getSession();
		Account account = (Account) session.getAttribute("Account");
		String redirection = "orderFS.jsp";
		Cart cart = null;
		
		session.removeAttribute("Error");
		
		if (account != null) {
			cart = account.getCart();
			
			List<Order> orderList;
			
			try {
				orderList = Order.searchOrders(account);
				session.setAttribute("OrderList", orderList);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		else {
			session.setAttribute("Error", UserMessages.USER_NOT_LOGGEDIN);
			redirection += "?error="+UserMessages.USER_NOT_LOGGEDIN;
		}

		response.sendRedirect(redirection);
	}
	
}
